//引入所需要的样式文件
document.write('<link rel="stylesheet" type="text/css" href="/plug/css/weui.css" />');
document.write('<link rel="stylesheet" type="text/css" href="/plug/css/example.css" />');
$(function () {
    //重写alert方法  直接alert('成功');
    window.alert = dialog_alert_open;
    //重写confirm方法
    window.confirm = dialog_confirm_open;
    /*//confirm调用示例
    window.confirm('确定要删除么?',function () {
        jQuery.post('/weixin/product/collect/doCollect', {'productId':pid,'memberId':'$!{memberId}'},function (data) {
            if(data == 'success'){
                $("#li_" + pid).remove();
            } else {
                alert('操作失败');
            }
        });
    },'')*/

})
//alert所需要的html代码
var alert_html = '<div class="weui_dialog_alert">'+
    '<div class="weui_mask"></div>'+
    '<div class="weui_dialog">'+
    '<div class="weui_dialog_hd"><strong class="weui_dialog_title">温馨提示</strong></div>'+
    '<div class="weui_dialog_bd">{info}</div>'+
    '<div class="weui_dialog_ft">'+
    '<a href="javascript:dialog_alert_close();" class="weui_btn_dialog primary">确定</a>'+
    '</div>'+
    '</div>'+
    '</div>';
//confirm所需要的html代码
var confirm_html = '<div class="weui_dialog_confirm">'+
    '<div class="weui_mask"></div>'+
    '<div class="weui_dialog">'+
    '<div class="weui_dialog_hd"><strong class="weui_dialog_title">温馨提示</strong></div>'+
    '<div class="weui_dialog_bd">{info}</div>'+
    '<div class="weui_dialog_ft">'+
    '<a href="#" class="weui_btn_dialog default">取消</a>'+
    '<a href="#" class="weui_btn_dialog primary">确定</a>'+
    '</div>'+
    '</div>'+
    '</div>';
//无操作提示框html代码
var toast_html = '<div id="weui_toast" style="display: none;">'+
    '<div class="weui_mask_transparent"></div>'+
    '<div class="weui_toast">'+
    '<i class="weui_icon_toast"></i>'+
    '<p class="weui_toast_content">{info}</p>'+
    '</div>'+
    '</div>';
//正在加载提示框代码
var loading_toast_html = '<div id="weui_loadingToast" class="weui_loading_toast" style="display:none;">'+
    '<div class="weui_mask_transparent"></div>'+
    '<div class="weui_toast">'+
    '<div class="weui_loading">'+
    '<div class="weui_loading_leaf weui_loading_leaf_0"></div>'+
    '<div class="weui_loading_leaf weui_loading_leaf_1"></div>'+
    '<div class="weui_loading_leaf weui_loading_leaf_2"></div>'+
    '<div class="weui_loading_leaf weui_loading_leaf_3"></div>'+
    '<div class="weui_loading_leaf weui_loading_leaf_4"></div>'+
    '<div class="weui_loading_leaf weui_loading_leaf_5"></div>'+
    '<div class="weui_loading_leaf weui_loading_leaf_6"></div>'+
    '<div class="weui_loading_leaf weui_loading_leaf_7"></div>'+
    '<div class="weui_loading_leaf weui_loading_leaf_8"></div>'+
    '<div class="weui_loading_leaf weui_loading_leaf_9"></div>'+
    '<div class="weui_loading_leaf weui_loading_leaf_10"></div>'+
    '<div class="weui_loading_leaf weui_loading_leaf_11"></div>'+
    '</div>'+
    '<p class="weui_toast_content">{info}</p>'+
    '</div>'+
    '</div>';
/**
 * alert方法重写实现
 * @param info  提示内容
 */
function dialog_alert_open(info){
    alert_html = alert_html.replace("{info}",info);
    //先要判断页面上之前是不是已经加入了这段html代码  有的话直接移除
    if($(".weui_dialog_alert").length > 0){
        $(".weui_dialog_alert").remove();
    }
    $(alert_html).appendTo($("body"));
    $(".weui_dialog_alert").show();
}
/**
 * 关闭alert弹出框
 */
function dialog_alert_close() {
    $(".weui_dialog_alert").hide();
}
/**
 * confirm方法重写实现
 * @param info  提示内容
 * @param fun_ok  点击确定执行的函数  没有传null
 * @param fun_cancel  点击取消执行的函数  没有传null
 * @returns {boolean}
 */
function dialog_confirm_open(info, fun_ok, fun_cancel){
    confirm_html = confirm_html.replace("{info}", info);
    //先要判断页面上之前是不是已经加入了这段html代码  有的话直接移除
    if($(".weui_dialog_confirm").length > 0){
        $(".weui_dialog_confirm").remove();
    }
    $(confirm_html).appendTo($("body"));
    $(".weui_dialog_confirm").show();
    $(".weui_dialog_confirm .default").click(function(){
        $(".weui_dialog_confirm").hide();
        if(typeof fun_cancel=='function')fun_cancel();
        return false;
    });
    $(".weui_dialog_confirm .primary").click(function(){
        $(".weui_dialog_confirm").hide();
        if(typeof fun_ok=='function')fun_ok();
        return true;
    });
    return false;
}
/**
 * 无操作提示框  提示框弹出后会在1秒之后关闭
 * @param info  提示信息
 */
function showToast(info) {
    toast_html = toast_html.replace("{info}",info);
    if($("#weui_toast").length > 0){
        $("#weui_toast").remove();
    }
    $(toast_html).appendTo($("body"));
    $("#weui_toast").show();
    setTimeout("$('#weui_toast').hide()",1000);//1秒后自动关闭
}
/**
 * 正在加载提示框
 * @param info  提示信息
 */
function showLoadingToast(info) {
    loading_toast_html = loading_toast_html.replace("{info}", info);
    if($("#weui_loadingToast").length > 0){
        $("#weui_loadingToast").remove();
    }
    $(loading_toast_html).appendTo($("body"));
    $("#weui_loadingToast").show();
}
/**
 * 关闭正在加载提示框
 */
function hideLoadingToast() {
    $("#weui_loadingToast").hide();
}
